package Bebetter.Day06;

import java.util.Scanner;
import java.util.Stack;

/**
 * @Author:galaxy_yan
 * @Date: 2022/11/27
 * @Time: 21:03
 * @Description
 */
public class day06B2 {
    public boolean chkParenthesis(String A, int n) {
//        2.存入堆栈进行比较
        Stack<Character> stack=new Stack<>();
        for (int i = 0; i < n; i++) {
            char ch=A.charAt(i);
            if(ch!=')'){
                stack.push(ch);
            }else {
                if(stack.isEmpty()){
                    return false;
                }else{
                    if(stack.pop()!='('){
                        return false;
                    }
                }
            }
        }
        if(stack.isEmpty()){
            return true;
        }
        return false;
    }
}
